<h2>Specials</h2>
<?php
require_once(dirname(__FILE__)."/../core/safeParam.php");

if (!isset($_GET['id']) && $_GET['action'] == "") {
  $results = $database->select("SELECT * FROM item_special WHERE rid = " . ARID . " ORDER by name ");
  echo ' 
    <a href="index.php?edit=specials&action=add" class="button"><img src="add.png" border="0"> Add Special</a>
    <table cellspacing="2" cellpadding="2" border="0" class="table"><tr>
                    <th>ID  </th>
                    <th>Special Name</th>
                    <th>Price</th>
    
                    <th>Action</th>
            </tr>';
  if ($results != false) {
    for ($i = 0; $i < count($results); $i++) {
      echo '<tr>
          <td>' . $results[$i]['id'] . '  </td>
          <td><a href="index.php?edit=specials&action=edit&id=' . $results[$i]['id'] . '">' . $results[$i]['name'] . ' </a></td>
          <td>' . price_format($results[$i]['price']) . ' </td>
          <td>
            <a href="index.php?edit=specials&action=edit&id=' . $results[$i]['id'] . '"><img src="application_edit.png"  border="0"> Edit </a> 
            <a href="../functions/specials.php?function=delete&id=' . $results[$i]['id'] . '"><img src="delete.png"  border="0"> Delete </a> 
          </td>
        </tr>';
    } //$i = 0; $i < count($results); $i++
  } //$results != false
  echo '</table>';
} //!isset($_GET['id']) && $_GET['action'] == ""
else {
  if ($_GET['id'] != "") {
    $results = $database->select("SELECT * FROM item_special WHERE id = " . $_GET['id'] . " ");
  } //$_GET['id'] != ""
?>
    
    
    
<form action="../functions/specials.php?function=<?php
  echo $_GET['action'];
?>" method="post" enctype="multipart/form-data">
                         <input type="hidden" name="rid" value="<?php
  echo ARID;
?>" />
                         <?php
  if ($_GET['id'] != "") {
    echo '<input type="hidden" name="id" value="' . $results[0]['id'] . '">';
  } //$_GET['id'] != ""
?>
                         <a href="javascript:openModal('#add-item-special',600,800)" class="button"><img src="add.png" border="0"> Add Item to this special</a>
						<table width="85%" border="0" cellspacing="5" cellpadding="3">
				  <tr>
					<td><strong>Item Name </strong></td>
					<td><input type="text" name="name" value="<?php
  echo $results[0]['name'];
?>" >

				
					
					</td>
				  </tr>
                    <tr>
					<td><strong>Upload Image </strong></td>
					<td><input type="file" name="image" /> 
                    <?php
  if ($_GET['id'] != "") {
    echo '<br><img src="../UserFiles/Image/product_photos/' . $results[0]['image'] . '">';
  } //$_GET['id'] != ""
?>
					
					</td>
				  </tr>
			
                    <tr>
					<td><strong>Price </strong></td>
					<td><input type="text" name="price" value="<?php
  echo $results[0]['price'];
?>" >

				
					
					</td>
				  </tr>
                        <tr>
					<td><strong>Pickup Discount </strong></td>
					<td><input type="text" name="discount" value="<?php
  echo $results[0]['discount'];
?>" >

				
					
					</td>
				  </tr>
                         <tr>
					<td><strong>Free toppings </strong></td>
					<td><input type="text" name="free_toppings" value="<?php
  echo $results[0]['free_toppings'];
?>" >

				
					
					</td>
				  </tr>
                            <tr>
					<td><strong>Toppings fee </strong></td>
					<td><input type="text" name="toppings_fee" value="<?php
  echo $results[0]['toppings_fee'];
?>" >

				
					
					</td>
				  </tr>
				    <tr>
					<td >
					<strong>Description:</strong>
                    </td><td>
<div >
<textarea name="description" cols="45" rows="10"><?php
  echo $results[0]['description'];
?></textarea>
					  </div></td>
					
				  </tr>
				
              
                  
                  	
   
                  
                   <tr>
					<td colspan="2"><input type="submit" name="submit" value="Save"></td>
					
				  </tr>
				</table>
				</form>    
           
       <?php
  if ($_GET['action'] == 'edit') {
?>       
              <h2>Configurable Items</h2>
            
          <?php
    $pizzas = $database->select("SELECT * from item_pizza where pid = " . $_GET['id'] . " order by pos");
    if ($pizzas == FALSE) {
      echo '<b style="color:red">No Configurable items exist!</b>';
    } //$pizzas == FALSE
    else {
?>  
            
              
 <SCRIPT type=text/javascript>
	$(function() {
		$("#tabs").tabs();
	});
	</SCRIPT>


<div id=tabs style="font-size:.8em" >
<ul>
<?php

      for ($i = 0; $i < count($pizzas); $i++) {
        echo '<li><a href="#tabs-' . $pizzas[$i]['id'] . '">' . $pizzas[$i]['name'] . '</a> </li>';
      } //$i = 0; $i < count($pizzas); $i++
?>
</ul>


<?php
      for ($i = 0; $i < count($pizzas); $i++) {
        echo '<div id="tabs-' . $pizzas[$i]['id'] . '">
<div style="text-align:right">
<a href="../functions/specials.php?function=delete-pizza&id=' . $pizzas[$i]['id'] . '&pid=' . $_GET['id'] . '"><img src="images/icons/remove.png" border="0"> Delete</a>
</div>
 	<form action="../functions/specials.php?function=edit-pizza" method="post">

  <input type="hidden" name="id" value="' . $pizzas[$i]['id'] . '" />
    <input type="hidden" name="pid" value="' . $_GET['id'] . '" />

<table width="100%" border="0" cellspacing="3" cellpadding="3">
  <tr>
    <td width="150">Name:</td>
    <td><input type="text" name="name" value="' . $pizzas[$i]['name'] . '"  /></td>
  </tr>
  
   
 

    <tr>
    <td width="150">Enable sides</td>
    <td>';
        unset($sides);
        $sides = unserialize($pizzas[$i]['sides']);
?>
 
  None<input type="checkbox" name="sides[0]" value="1" <?php
        if ($sides[0] == 1) {
          echo 'checked="checked"';
        } //$sides[0] == 1
?>style="width:25px"   /> 
  Left<input style="width:25px"  type="checkbox" name="sides[1]"  value="1" <?php
        if ($sides[1] == 1) {
          echo 'checked="checked"';
        } //$sides[1] == 1
?>  /> 
  Whole<input style="width:25px"  type="checkbox" name="sides[2]" value="1" <?php
        if ($sides[2] == 1) {
          echo 'checked="checked"';
        } //$sides[2] == 1
?>  /> 
  Right<input style="width:25px"  type="checkbox" name="sides[3]" value="1" <?php
        if ($sides[3] == 1) {
          echo 'checked="checked"';
        } //$sides[3] == 1
?>  /> 
 </td>
<?php

        echo ' </tr>
  
    <tr>
    <td width="150">Position:</td>
    <td><input type="text" name="pos"   value="' . $pizzas[$i]['pos'] . '"  /></td>
  </tr>
  <tr><td>Base  (comma seperated)</td>
       <td><textarea name="base"  style="width:400px;height:150px">' . $pizzas[$i]['base'] . '</textarea></td>
  </tr> 
<tr>
    <td>Toppings</td>
       <td><textarea name="toppings"  style="width:400px;height:150px">' . $pizzas[$i]['toppings'] . '</textarea></td>
  </tr> 

<tr>
    <td>Sauce</td>
       <td><textarea name="sauce"  style="width:400px;height:150px">' . $pizzas[$i]['sauce'] . '</textarea></td>
  </tr> 
   <tr>
    <td>Pop</td>
       <td><textarea name="pop"  style="width:400px;height:150px">' . $pizzas[$i]['pop'] . '</textarea></td>
  </tr>

 
   
    <td>&nbsp;</td>
    <td><input type="submit"  value="Save"/></td>
  </tr> 
</table></form>


</div>';
      } //$i = 0; $i < count($pizzas); $i++
?>


</div>
              
            <?php
    }
  } //$_GET['action'] == 'edit'
?>    
                <div style="display:none">
                <div id="add-item-special">
              	<form action="../functions/specials.php?function=add-pizza" method="post">

  <input type="hidden" name="rid" value="<?php
  echo ARID;
?>" />
   <input type="hidden" name="pid" value="<?php
  echo $_GET['id'];
?>" />

<table width="100%" border="0" cellspacing="3" cellpadding="3">
  <tr>
    <td width="150">Name:</td>
    <td><input type="text" name="name" value=""  /></td>
  </tr>
  
  
  
  
     

    <tr>
    <td width="150">Enable sides</td>
    <td>
    
 
    
    None<input type="checkbox" name="sides[0]" value="1" style="width:25px"  /> Left<input style="width:25px"  type="checkbox" name="sides[01]" value="1"  /> Whole<input type="checkbox" name="sides[02]" value="1" style="width:25px"    /> Right<input  style="width:25px"  type="checkbox" name="sides[3]" value="1"  /> </td>
  </tr>
  
   <tr>
    <td width="150">Position:</td>
    <td><input type="text" name="pos"     /></td>
  </tr>
  <tr><td>Base  (comma seperated)</td>
       <td><textarea name="base"  style="width:400px;height:150px"></textarea></td>
  </tr> 
  <tr>
    <td>Sauce</td>
       <td><textarea name="sauce"  style="width:400px;height:150px"></textarea></td>
  </tr> 
    <tr>
    <td>Pop</td>
       <td><textarea name="pop"  style="width:400px;height:150px"></textarea></td>
  </tr> 
<tr>
    <td>Toppings</td>
       <td><textarea name="toppings"  style="width:400px;height:150px"></textarea></td>
  </tr> 



    
    <td>&nbsp;</td>
    <td><input type="submit"  value="Save"/></td>
  </tr> 
</table></form>
                </div>
                </div>
    <?php

}
?>
